﻿using ComposantReferentiel;
using GenericWin;
using GeneralServices.Data;
using GeneralServices.ViewModel;
using System;
using System.Collections.Generic;

namespace WpfApplication1
{
    /// <summary>
    /// Logique d'interaction pour Test.xaml
    /// </summary>
    public partial class Test : GenericUserControl, IComposantModification
    {
        public Test()
        {
            InitializeComponent();
            this.VM = this.Resources["vm"] as ViewModelBase;
        }

        #region IComposantModification Membres

        public void AfterCreate(ref object o)
        {
            EMB_EMBALLAGE emb = o as EMB_EMBALLAGE;
            if (emb != null)
            {
                emb.DATE_HEURE_CREATION = DateTime.Now;
                emb.DATE_HEURE_MODIF = DateTime.Now;
                emb.RESP_MISE_A_JOUR = "TITI";
            }
        }

        public object BeforeUpdate(object o)
        {
            EMB_EMBALLAGE emb = o as EMB_EMBALLAGE;

            if (emb != null)
            {
                emb.DATE_HEURE_MODIF = DateTime.Now;
                emb.RESP_MISE_A_JOUR = "TITI";
            }

            return emb;
        }

        public System.Data.Entity.DbContext GetContext()
        {
            return new Entities();
        }

        public ParamExportCSV GetParam()
        {
            return new ParamExportCSV
            {
                Separateur = ";",
                Path = "C:\\Users\\legouellecs\\Desktop\\test.csv",
                Header = new ReadAndWrite.HeaderCSV
                {
                    Headers = new List<string> { "CODE_EMBALLAGE","ATELIER","TOP_ACTIF","TOP_EMBA_AVEC_HAUTEUR","TOP_COUVERCLE","FLUX_UTILISATION","CODE_PLAN","OBSERVATION","MARCHE"}
                }
            };
        }

        public void CloseReferentielComposant()
        {
            //TestVM vm = this.Resources["vm"] as TestVM;
            if (VM is IVMCloseRefenretielComposant)
                (VM as TestVM).Close(this);
        }

        #endregion
    }
}
